home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 March / EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso / earcd / program / sprprcdr.lha / InputText.AMOS / InputText.amosSourceCode
AMOS Source Code  |  1996-01-26  |  3KB  |  96 lines

  1. '   ******************************************************** 
  2. '   ***                                                  *** 
  3. '   ***                Input Text Procedure              *** 
  4. '   ***                                                  *** 
  5. '   ***                        by                        *** 
  6. '   ***                                                  *** 
  7. '   ***                   Joseph Bolin                   *** 
  8. '   ***                                                  *** 
  9. '   ******************************************************** 
  10. Screen Open 0,320,200,8,Lowres
  11. Palette $0,$FFF,$444,,$F00 : Curs Off : Cls 2
  12. _INPUT[64,96,64,24,"Enter some text here:",1,0,3]
  13. _INPUT[60,108,64,24,"Another example of this input routine",4,0,3]
  14.  
  15.  
  16. Procedure _INPUT[_XPOS,_YPOS,_LENGTH,_SHOW,_DEFAULT$,_PEN,_PAPER,_CURSPEN]
  17.  
  18.    ' Replacement for the input command;  May be at any position on the screen 
  19.    '  
  20.    '    
  21.    ' Inputs:  _XPOS,_YPOS  Coordinates of input; Not limited to mutiples of 8 
  22.    '          _LENGTH      Maximum length of string 
  23.    '          _SHOW        Length of shown section
  24.    '          _DEFAULT$    Default reply
  25.    '          _PEN         Color of text
  26.    '          _PAPER       Background of text 
  27.    '          _CURSPEN     Color of cursor
  28.    '
  29.    ' Output:  Param$       Inputed string 
  30.    
  31.    INP$=_DEFAULT$
  32.    SPOS=Len(INP$)+1-_SHOW : CPOS=Min(_SHOW-1,Len(INP$))
  33.    If SPOS<0 Then SPOS=0
  34.    Do 
  35.       Ink _PEN,_PAPER
  36.       Text _XPOS,_YPOS+Text Base,Left$(Mid$(INP$,SPOS+1,_SHOW-1)+Space$(_SHOW),_SHOW)
  37.       Ink _CURSPEN : Bar _XPOS+CPOS*8,_YPOS+6 To _XPOS+CPOS*8+7,_YPOS+7
  38.       Repeat 
  39.          KY$=Inkey$
  40.       Until KY$<>""
  41.       SC=Scancode : KS=Key Shift
  42.       If KY$=Chr$(13) Then Exit 
  43.       If KY$=Chr$(29)
  44.          If KS=0 : Gosub MLEFT : End If 
  45.          If KS and 3
  46.             Gosub MLEFT
  47.             Repeat 
  48.                Gosub MLEFT
  49.             Until Mid$(INP$,SPOS+CPOS,1)=" " or SPOS+CPOS=0
  50.          End If 
  51.          If KS and 24 : SPOS=0 : CPOS=0 : End If 
  52.          Goto DN
  53.       End If 
  54.       If KY$=Chr$(28)
  55.          If KS=0 : Gosub MRIGHT : End If 
  56.          If KS and 3
  57.             Repeat 
  58.                Gosub MRIGHT
  59.             Until Mid$(INP$,SPOS+CPOS,1)=" " or SPOS+CPOS=Len(INP$)
  60.          End If 
  61.          If KS and 24
  62.             SPOS=Len(INP$)+1-_SHOW : CPOS=Min(_SHOW-1,Len(INP$))
  63.             If SPOS<0 : SPOS=0 : End If 
  64.          End If 
  65.          Goto DN
  66.       End If 
  67.       If KY$=Chr$(8)
  68.          If SPOS+CPOS>0 : INP$=Left$(INP$,SPOS+CPOS-1)+Right$(INP$,Len(INP$)-SPOS-CPOS) : End If 
  69.          Gosub MLEFT : Goto DN
  70.       End If 
  71.       If SC=70
  72.          If SPOS+CPOS<Len(INP$)
  73.             INP$=Left$(INP$,SPOS+CPOS)+Right$(INP$,Len(INP$)-SPOS-CPOS-1)
  74.          End If 
  75.          Goto DN
  76.       End If 
  77.       If Len(INP$)>=_LENGTH Then Goto DN
  78.       If KY$=Chr$(0) or KY$=Chr$(27) Then Goto DN
  79.       INP$=Left$(INP$,SPOS+CPOS)+KY$+Right$(INP$,Len(INP$)-SPOS-CPOS)
  80.       Gosub MRIGHT
  81.       DN:
  82.    Loop 
  83.    Ink _PEN,_PAPER
  84.    Text _XPOS,_YPOS+Text Base,Left$(Mid$(INP$,SPOS+1,_SHOW-1)+Space$(_SHOW),_SHOW)
  85.    Pop Proc[INP$]
  86.    
  87.    MRIGHT:
  88.    If SPOS+CPOS=Len(INP$) Then Return 
  89.    If CPOS>(_SHOW*2)/3 and SPOS+CPOS<Len(INP$) Then Inc SPOS Else Inc CPOS
  90.    Return 
  91.    
  92.    MLEFT:
  93.    If SPOS=0 and CPOS=0 Then Return 
  94.    If CPOS<_SHOW/3 and SPOS>0 Then Dec SPOS Else Dec CPOS
  95.    Return 
  96. End Proc